package com.bfd.archetype.controller;


import com.bfd.archetype.entity.Users;
import com.bfd.archetype.service.IUsersService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author ygy
 * @since 2020-10-15
 */
@RestController
@RequestMapping("/users")
@Api(tags = "用户信息管理")
@Slf4j
public class UsersController {

    @ApiOperation(value = "list",tags = "查询list")
    @ApiImplicitParams(
            {@ApiImplicitParam(name = "name", value = "名称", required = true, paramType = "query")}
    )
    @GetMapping("list")
    public String userList(@RequestParam String name) {
        List<Users> list = usersService.list();
        log.debug("list为:{}",list);
        return list.toString();

    }

    @Autowired
    private IUsersService usersService;


    @ApiOperation(value = "add",tags = "增加一个用户")
    @PostMapping("add")
    public boolean add(@RequestBody Users users) {
        boolean save = usersService.save(users);
        return save;
    }


    @ApiOperation(value = "del",tags = "删除")
    @PostMapping("del")
    public boolean del(@RequestParam Long id) {
        boolean save = usersService.removeById(id);
        return save;
    }

}
